Linux, GNU GCC, ld, version scripts and the ELF binary format -- How does it work? [closed]
Posted
by
themoondothshine
on Programmers
See other posts from Programmers
or by themoondothshine
Published on 2011-01-12T04:43:56Z
Indexed on
2011/01/12
4:59 UTC
Read the original article
Hit count: 207
I'm trying to learn more about library versioning in Linux and how to put it all to work. Here's the context:
I have two versions of a dynamic library which expose the same set of interfaces, say libsome1.so
and libsome2.so
. An application is linked against libsome1.so
.
This application uses libdl.so
to dynamically load another module, say libmagic.so
. Now libmagic.so
is linked against libsome2.so
. Obviously, without using linker scripts to hide symbols in libmagic.so
, at run-time all calls to interfaces in libsome2.so
are resolved to libsome1.so
. This can be confirmed by checking the value returned by libVersion()
against the value of the macro LIB_VERSION
.
So I try next to compile and link libmagic.so
with a linker script which hides all symbols except 3 which are defined in libmagic.so
and are exported by it. This works... Or at least libVersion()
and LIB_VERSION
values match (and it reports version 2 not 1).
However, when some data structures are serialized to disk, I noticed some corruption. In the application's directory if I delete libsome1.so
and create a soft link in its place to point to libsome2.so
, everything works as expected and the same corruption does not happen.
I can't help but think that this may be caused due to some conflict in the run-time linker's resolution of symbols. I've tried many things, like trying to link libsome2.so
so that all symbols are alised to symbol@@VER_2
(which I am still confused about because the command nm -CD libsome2.so
still lists symbols as symbol
and not symbol@@VER_2
), but nothing seems to work.
What am I doing wrong?
© Programmers or respective owner